<?php
/**
 * Demo Index
 */

class indexAction
{
	private $_tpl;
	private $_logo='http://img01.taobaocdn.com/imgextra/i1/135326559/T2bfkbXnFaXXXXXXXX_!!135326559.png';

	public $route;

	public function __construct() {
		$this->_tpl = new TPL();
		$rt=Base::getRoute();
		$this->route='r=' . $rt['c'] . '/' . $rt['a'];
	}

    public function index() {
		$meta=array(
			array('name'=>'Title', 'content'=>'零食 吃货 海涛网络超市 海涛零食 海涛超市 化妆品 便宜，方便，放心的网上平价超市'),		
			array('name'=>'Author', 'content'=>'www.haitaocs.com'),
			array('name'=>'Subject', 'content'=>'海涛零食 海涛超市 零食 化妆品 便宜，方便，放心的网上平价超市'),
			array('name'=>'Description', 'content'=>'提供各种时尚，可口的美味零食，以及流行美丽的化妆护理用品'),
			array('name'=>'Keywords', 'content'=>'零食;吃货;海涛零食;海涛超市;时尚美食;美味零食'),
			array('name'=>'Generator', 'content'=>'www.haitaocs.com'),
			array('name'=>'Language', 'content'=>'zh-CN'),
			array('name'=>'Abstract', 'content'=>'本店提供各种零食，小吃，特产以及化妆护理用品'),
			array('name'=>'Copyright', 'content'=>'www.haitaocs.com'),
			array('name'=>'Publisher', 'content'=>'www.haitaocs.com'),
			array('name'=>'Designer', 'content'=>'www.haitaocs.com'),
			array('name'=>'Robots', 'content'=>'All'),

		);
		$product=new productModel();
		$c=intval(Base::getRequest('c'));

		/**
		  *处理导航栏
		  */
		$ca=new caModel();	
		$ca_tree=$ca->getCategoryTree('lingshi');
		
		if($c<=0) 
			$c_desc='首页';
		else {
			foreach($ca_tree as $item)
				if($c==$item['father']['id'] || array_search($c, $item['child'])=='id') {
					$c_desc=$item['father']['desc'];
					break;
				}
		}

		$nav_content=$this->_tpl->getRender('nav.html', array('c'=>$c, 'tree'=>$ca_tree, 'route'=>$this->route));

		//渲染头部
		$header_content=$this->_tpl->getRender('header.html', array('taobao_home_url'=>'#', 'logo_img_link'=>$this->_logo));	
		
		//渲染TOP广告
		$ad_top_content=$this->_tpl->getRender('ad_top.html', '');    
	
		//处理正文的内容
		$first=$this->_tpl->getRender('product.html', array('products'=>$product->getProduct($c, 0, 8),  'buy_pic_link'=>'http://img04.taobaocdn.com/imgextra/i4/135326559/T24YckXmlXXXXXXXXX_!!135326559.gif'));	
		$main_content=$this->_tpl->getRender('main.html', array('c'=>$c, 'first'=>$first));
	
		//
		$foot_content=$this->_tpl->getRender('footer.html', array());	
		$this->_tpl->render('index.html', array(
				'meta_info'=>$meta,
				'title'=>'海涛网络超市-海涛零食-' . $c_desc,
				'css_info'=>array(CSS_URL . 'styles.css'), 
				'header_content'=>$header_content,
				'nav_content'=>$nav_content,
				'ad_top_content'=>$ad_top_content,
				'main_content'=>$main_content,
				'footer_content'=>$foot_content,
				'js_info'=>array(
						'//lib.sinaapp.com/js/jquery/2.0/jquery.min.js',
						'//cdn.jsdelivr.net/slidesjs/1.1.9/slides.min.jquery.js',
						'//cdn.jsdelivr.net/masonry/2.1.08/jquery.masonry.min.js',
						JS_URL . 'jquery.infinitescroll.min.js',
						JS_URL . 'jz.js',			
					),
			)
		);
    }
    
    public function utf2gbk() {
        $word=Base::getRequest('w');

        echo urlencode(iconv('UTF-8', 'GBK', $word));
    }
    
    public function counts() {
        $product=new productModel();
        echo $product->updateClickCounts();
    }
    
	public function getProduct() {
		$product=new productModel();
		$c=intval(Base::getRequest('c'));
		$page=intval(Base::getRequest('page'));

		$this->_tpl->render('product.html', array('products'=>$product->getProduct($c, $page), 'buy_pic_link'=>'http://img04.taobaocdn.com/imgextra/i4/135326559/T24YckXmlXXXXXXXXX_!!135326559.gif'));
	}
}

/* ------ EOF ------ */
